"use strict";

var C = require('./lib/common.js'),
    path = require('path'),
    app = require('./lib/app.js');      

/**
 * @module Nodeframe
 * @summary The nodeframe object
 * @mixes Common
 */
var Nf = module.exports = C._.extend(C, {

    /**
     * The nodeframe application instance
     * @memberof module:Nodeframe
     * @type {App}
     */
    app: app,

    /**
     * Service facade
     * @memberof module:Nodeframe
     * @type {object}
     */
    $: app.$,

    /**
     * @method
     * @param {completionCallback} [cb]
     */
    start: function(cb) {
        app.bootstrap(function (err) {
            if (err) {
                if (cb) return cb(err);
                throw err;
            }

            cb && cb();
        });
    },

    require: function(name) {
        C.excludeDotChar('module name', name);

        return require(path.resolve(__dirname, './node_modules/' + name));
    }
});

/**
 * Completion callback
 *
 * @callback completionCallback
 * @param {*} [err] - The error object if error occurrid
 */
